package com.rd.student.jiaji.class3.sunguowei.day27;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class TestPrint {
    public static void main(String[] args) throws Exception{
        //开始重新定向输入
        FileInputStream fis=new FileInputStream("in.txt");
        System.setIn(fis);

        Scanner scanner=new Scanner(System.in);
        StringBuilder builder=new StringBuilder();
//        while (scanner.hasNext()){
        while (scanner.hasNextLine()){
//            System.out.println(scanner.next());
//            builder.append(scanner.next());
            builder.append(scanner.nextLine()+"\n");
        }
        System.out.println(builder);
        PrintStream ps=new PrintStream(
                new FileOutputStream("Out.txt"));
        System.setOut(ps);

        System.out.println(builder);
        ps.close();
        fis.close();
    }

    public static void testOut()throws Exception{
        PrintStream ps=new PrintStream(
                new FileOutputStream("Out.txt"));
        System.setOut(ps);

        System.out.println("hello out txt");
        ps.close();
    }
    public static void test()throws Exception{
        FileOutputStream fos=new FileOutputStream("streamPrint.txt");//节点流
        PrintStream ps=new PrintStream(fos);//处理流
        ps.println("hello PrintStream");
        System.out.println("hello PrintStream");
        //在使用处理流时，只要关闭处理流就可，系统会自动关闭处理流包装的节点流
        ps.close();
    }
}
